package com.aaa.inbound.service.impl;

import com.aaa.entity.inbound.ReceiveDetail;
import com.aaa.entity.inbound.WarehousingDetail;
import com.aaa.inbound.mapper.WarehousingDetailMapper;
import com.aaa.inbound.service.WarehousingDetailService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aaa
 * @since 2020-11-25
 */
@Service
public class WarehousingDetailServiceImpl extends ServiceImpl<WarehousingDetailMapper, WarehousingDetail> implements WarehousingDetailService {

    @Autowired
    private WarehousingDetailMapper detailMapper;

    @Override
    public boolean saveDetail(WarehousingDetail detail) {
        if (detail.getId()!=null){
            if (findById(detail.getPid(),detail.getCommodityid())){
                detailMapper.updDetail(detail.getCommodityid(), detail.getQty());
                return true;
            }
        }
        detailMapper.insert(detail);
        return false;
    }

    public boolean findById(Long pid,Long commodityid) {
        QueryWrapper<WarehousingDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("pid",pid);
        wrapper.eq("commodityid",commodityid);
        WarehousingDetail warehousingDetail = detailMapper.selectOne(wrapper);
        if (warehousingDetail==null){
            return false;
        }else {
            return true;
        }
    }
}
